# -*- coding: utf-8 -*-

import time
import hashlib
from base import UserCase, Runner, TestSuite

class Case(UserCase):

    def test_session_list(self):
        res = self.c.open('/api/system/list')
        self.assertEqual(res['code'], 0)

    def test_session_read(self):
        res = self.c.open('/api/system/read', {'name': 'front_admin_template'})
        self.assertEqual(res['code'], 0)

    def test_session_update(self):
        res = self.c.open('/api/system/read', {'name': 'front_admin_template'})
        self.assertEqual(res['code'], 0)
        value = res['data']['value']

        p = {
            'name': 'front_admin_template',
            'value': self.randchar(16),
        }

        res = self.c.open('/api/system/update', p)
        self.assertEqual(res['code'], 0)

        res = self.c.open('/api/system/read', {'name': 'front_admin_template'})
        self.assertEqual(res['code'], 0)
        self.assertEqual(res['data']['value'], p['value'])
        self.assertEqual(abs(res['data']['update'] - time.time()) < 10, True)

        p = {
            'name': 'front_admin_template',
            'value': value,
        }

        res = self.c.open('/api/system/update', p)
        self.assertEqual(res['code'], 0)



test_list = [
    'test_session_list',
    'test_session_read',
    'test_session_update',
]
Suite = TestSuite([Case(t) for t in test_list])


if __name__ == '__main__':
    Runner.run(Suite)



